﻿using System;
using System.Collections.Generic;
using Autodesk.Revit.DB;
using YArchitech.HCLoad.Utils;
using YArchitech.Revit;

namespace YArchitech.HCLoad.Export
{
	public class HcWallData
	{
		public Wall Wall
		{
			get
			{
				return this.m_wall;
			}
		}

		public ElementId Id
		{
			get
			{
				return this.m_wall.Id;
			}
		}

		public string Name
		{
			get
			{
				return this.m_wall.Name;
			}
		}

		public HashSet<ElementId> AdjacentSpaceIds
		{
			get
			{
				return this.m_setAdjacentSpaceId;
			}
		}

		public HashSet<Opening> Openings
		{
			get
			{
				return this.m_setOpening;
			}
		}

		public double Azimuth
		{
			get
			{
				return this.m_dAzimuth;
			}
		}

		public double Height
		{
			get
			{
				return this.m_dHeight;
			}
		}

		public double Width
		{
			get
			{
				return this.m_dWidth;
			}
		}

		public HcWallData(Wall wall)
		{
			this.m_wall = wall;
			this.m_setAdjacentSpaceId = new HashSet<ElementId>();
			this.m_setOpening = new HashSet<Opening>();
			this.GetWallInfo();
		}

		public string GetSurfaceTypeStr()
		{
			string result = "ExteriorWall";
			if (this.m_setAdjacentSpaceId != null && this.m_setAdjacentSpaceId.Count > 1)
			{
				result = "InteriorWall";
			}
			return result;
		}

		public string GetConstructionIdRefStr()
		{
			return "";
		}

		private bool GetWallInfo()
		{
			LocationCurve locationCurve = (LocationCurve)this.m_wall.Location;
			XYZ hyendPoint = locationCurve.Curve.GetEndPoint(0);
			XYZ hyendPoint2 = locationCurve.Curve.GetEndPoint(1);
			UV uv = new UV(1.0, 0.0);
			UV uv2 = new UV(hyendPoint2.X - hyendPoint.X, hyendPoint2.Y - hyendPoint.Y);
			this.m_dAzimuth = uv2.AngleTo(uv);
			this.m_dWidth = HcUnit.LengthConverFromAPI(this.m_wall.Document, uv2.GetLength());
			ElementId elementId = this.m_wall.get_Parameter(BuiltInParameter.WALL_BASE_CONSTRAINT).AsElementId();
			ElementId elementId2 = this.m_wall.get_Parameter(BuiltInParameter.WALL_HEIGHT_TYPE).AsElementId();
			Level level = (Level)this.m_wall.Document.GetElementById(elementId);
			Level level2 = (Level)this.m_wall.Document.GetElementById(elementId2);
			if (level == null || level2 == null)
			{
				return false;
			}
			this.m_dHeight = HcUnit.LengthConverFromAPI(this.m_wall.Document, level2.Elevation - level.Elevation);
			return true;
		}

		private Wall m_wall;

		private HashSet<ElementId> m_setAdjacentSpaceId;

		private HashSet<Opening> m_setOpening;

		private double m_dAzimuth;

		private double m_dHeight;

		private double m_dWidth;
	}
}
